﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace Yoozoo.Gameplay.Liberty
{
    [Serializable]
    public class BluePrintPoints
    {
        public List<string> names;
        public List<Vector3> positions;
        public List<Quaternion> rotations;
        public List<Vector3> eulerAngles;
        public List<Vector3> scales;
        public List<Vector3> forwards;
        private Dictionary<string, BluePrintPoint> data;

        public BluePrintPoints(int capacity)
        {
            this.names = new List<string>(capacity);
            this.positions = new List<Vector3>(capacity);
            this.rotations = new List<Quaternion>(capacity);
            this.eulerAngles = new List<Vector3>(capacity);
            this.scales = new List<Vector3>(capacity);
            this.forwards = new List<Vector3>(capacity);
        }

        public void Add(Transform t)
        {
            this.names.Add(t.name);
            this.positions.Add(t.position);
            this.rotations.Add(t.rotation);
            this.eulerAngles.Add(t.eulerAngles);
            this.scales.Add(t.lossyScale);
            this.forwards.Add(t.forward);
        }

        public Dictionary<string, BluePrintPoint> Data
        {
            get
            {
                if (this.data == null)
                {
                    var count = this.names.Count;
                    this.data = new Dictionary<string, BluePrintPoint>(count);
                    for (int i = 0; i < count; i++)
                    {
                        this.data.Add(this.names[i], new BluePrintPoint()
                        {
                            position = this.positions[i],
                            rotation = this.rotations[i],
                            eulerAngles = this.eulerAngles[i],
                            lossyScale = this.scales[i],
                            forward = this.forwards[i],
                        });
                    }
                }

                return this.data;
            }
        }
    }

    public class BluePrintPoint
    {
        public Vector3 position;
        public Quaternion rotation;
        public Vector3 eulerAngles;
        public Vector3 lossyScale;
        public Vector3 forward;
    }
}